package com.zhuoyue.web.controller;


import com.zhuoyue.biz.core.api.service.DeviceActionService;
import com.zhuoyue.common.aop.auth.CheckLogin;

import com.zhuoyue.common.dto.ControllerResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

@RestController
@Scope("prototype")
@RequestMapping("/api/action")
@Validated
@Slf4j(topic = "DeviceAction")
/**
 * @ClassName: AppDeviceActionController
 * @Description:设备动态信息操作接口
 *  备Action单独接口增删改查
 * @author wjming
 * @Date 2021/2/14 19:40
 */
public class AppDeviceActionController {
    @Autowired
    private DeviceActionService deviceActionService;


    @PutMapping("/modify")
    @CheckLogin
    public ControllerResult updateDeviceAction(@RequestParam @NotBlank(message = "设备ID不能为空！") String deviceId, String action) {
        log.info("request -> [updateDeviceAction] -> [{},{}]", deviceId, action);
        Boolean aBoolean = deviceActionService.updateDeviceActionById(deviceId, action);
        if (!aBoolean) {
            return ControllerResult.toParamFail("设备Action配置失败");
        }
        return ControllerResult.toReturnMessageSuccess("设备Action配置成功");
    }
}
